import moment from 'moment'
import { Request, Response } from 'express';
import type { DataNode, TreeProps } from 'antd/es/tree';
import { random } from 'lodash';
// const Mock = require('mockjs')
// console.log('Mock---',Mock)
// Mock.mobile_prefix = ["134", "135", "136", "137", "138", "139", "150", "151","152", "157", "158", "159", "130","131", "132", "155", "156", "133", "153"];
// export function getMobile() {
//  return Mock.Random(1, Mock.mobile_prefix) + Mock.Random(8, Mock.numeric);
// }

// Mock.email_suffix = ["@qq.com", "@163.com","@163.net",  "@126.com", "@sina.com"];
// export function getEmail() {
// 	let opt = Mock.numeric + Mock.lowerCase + Mock.upperCase
// 	return Random( Mock.randomInt(4, 10), opt) + Random(1, Mock.email_suffix);
// }

// Mock.depData = [
// {
//   name:'研发部门',
//   code:'001'
// },
// {
//   name:'测试部门',
//   code:'002'
// },
// {
//   name:'市场部门',
//   code:'003'
// },
// {
//   name:'运维部门',
//   code:'004'
// },
// {
//   name:'财务部门',
//   code:'005'
// }
// ];
//部门数据
// export function getDepData(type) {
// 	return Random(1, Mock.depData[type]);
// }

const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(true);
      }, time);
    });
  };
 let userTreeData = [
                      {
                        title: 'XX公司',
                        key: '0-0',
                        children: [
                          {
                            title: '分公司1',
                            key: '0-0-1',
                            children: [
                              {
                                title: '部门1-1',
                                key: '0-0-1-1',
                                disableCheckbox: true,
                                isLeaf: true,
                              },
                              {
                                title: '部门1-2',
                                key: '0-0-1-2',
                                isLeaf: true,
                              },
                            ],
                          },
                          {
                            title: '分公司2',
                            key: '0-0-2',
                            children: [
                              {
                                title: '部门2-1',
                                key: '0-0-2-1',
                                isLeaf: true,
                              },
                              {
                                title: '部门2-2',
                                key: '0-0-2-2',
                                isLeaf: true,
                              },
                              {
                                title: '部门2-3',
                                key: '0-0-2-3',
                                isLeaf: true,
                              },
                              {
                                title: '部门2-4',
                                key: '0-0-2-4',
                                isLeaf: true,
                              }
                            ],
                          },
                          {
                            title: '分公司3',
                            key: '0-0-3',
                            children: [
                              {
                                title: '部门3-1',
                                key: '0-0-3-1',
                              },
                              {
                                title: '部门3-2',
                                key: '0-0-3-2',
                              },
                              {
                                title: '部门3-3',
                                key: '0-0-3-3',
                              },
                              {
                                title: '部门3-4',
                                key: '0-0-3-4',
                              }
                            ],
                          },
                        ],
                      }
                    ]

let userTableHead=[
 {
   code:'roleId',
   name:'用户编号',
   search:true,
   isSort:false,
 },
 {
    code:'roleName',
    name:'用户账号',
    search:false,
    isSort:true,
  },
  {
    code:'nickname',
    name:'用户昵称',
    search:false,
    isSort:false,
  },
  {
      code:'deptCode',
      name:'部门code',
      search:false,
      isSort:false,
  },
  {
      code:'deptName',
      name:'部门',
      search:false,
      isSort:false,
   },
   {
       code:'phone',
       name:'手机号码',
       search:true,
       isSort:false,
    },
    {
       code:'status',
       name:'状态',
       search:true,
       isSort:false,
    },
]

// let userTableList = Mock.mock({
//     roleId:"@cword",
//     roleName:"@name()",
//     nickname :"@cname()",
// //     deptCode:getDepData('code'),
// //     deptName:getDepData('name'),
//     phone:getMobile(),
// //     email:getEmail(),
// //     status:Random.boolean(1, 4, true),
// })
let userTableList = []
for (let i = 0; i < 24; i += 1) {
  userTableList.push({
    key: i,
    roleId:'roleId'+i,
    roleName: 'roleName'+i,
    nickname: 'nickname'+i,
    deptCode: 'deptCode'+i,
    deptName: 'deptName'+i,
    phone: '18297859347',
    status: true,
    createdAt: Date.now() - Math.floor(Math.random() * 2000),
    progress: Math.ceil(Math.random() * 100) + 1,
    memo:
      i % 2 === 1
        ? '很长很长很长很长很长很长很长的文字要展示但是要留下尾巴'
        : '简短备注文案',
  });
}

  const treeData: DataNode = {
      userTreeData,
  };
  async function userTData(req: Request, res: Response) {
      await waitTime(2000);
      return res.json({success: true,data:treeData});
  }

  const tableData: DataNode = {
        userTableHead,
        userTableList,
        total:userTableList.length
    };
    async function userTableData(req: Request, res: Response) {
        await waitTime(2000);
        return res.json({success: true,data:tableData});
    }

  export default{
      'GET  /system/role/list': userTableData,
      'GET  /system/role/listTree': userTData,
      'POST  /system/role/list': userTData,
  }
